import AMapLoader from "@amap/amap-jsapi-loader";

export default defineNuxtPlugin(async () => {
  const config = useRuntimeConfig();
  if (!config.public.amapKey) {
    return {};
  }

  // 服务平台：Web端(JS API)
  window._AMapSecurityConfig = {
    securityJsCode: config.public.amapCode,
  };

  return {
    provide: {
      _AMap: await AMapLoader.load({
        key: config.public.amapKey,
        version: "2.0",
      }),
    },
  };
});